package com.beidouapp.initialize;

import java.util.HashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.beidouapp.service.CityService;

@Service
public class CityInitializeBean implements InitializingBean{

	private final static Logger log = LoggerFactory.getLogger(CityInitializeBean.class);
	
	@Autowired
	private CityService cityService;
	
	@Override
	public void afterPropertiesSet() throws Exception {
		String master = System.getProperty("server.master");
		if (master == null || !master.equalsIgnoreCase("true"))
		{
			return;
		}
		Runnable runnable =  new Runnable(){
			@Override
			public void run() {
				 try {
					Thread.sleep(20000);
					boolean flag = cityService.storeAllAddressList(new HashMap<String, Object>());
					if (!flag)
					{
						log.error("启动获取省市区县镇异常");
					}
				} catch (Exception e) {
					//ignore
				}
			}
		};
		Thread th = new Thread(runnable);
		th.start();
	}

}
